import java.util.HashMap;
import java.util.Scanner;
import java.util.Stack;


public class Calculator {
	
	HashMap<String, Integer> out = new HashMap<>();
	HashMap<String, Integer> in = new HashMap<>();
	
	public Calculator() {
		out.put("+", 1);
		out.put("-", 1);
		out.put("*", 3);
		out.put("/", 3);
		out.put("%", 3);
		out.put("^", 5);
		out.put("(", 7);
		
		in.put("#",0);
		in.put("(",0);
		in.put("+",2);
		in.put("-",2);
		in.put("*",4);
		in.put("/",4);
		in.put("%",4);
		in.put("^",5);
	}
	
	public static void main(String[] args) {
		System.out.println("Input an expression,end with '#'");
		Scanner scanner = new Scanner(System.in);
		String s = scanner.nextLine();
		scanner.close();
		s = s.replace(" ","");
		char[] input = s.toCharArray();
		try {
			System.out.println(new Calculator().cal(input));
		} catch (Exception e) {
			System.out.println("Error!");
		}
	}

	public double cal(char[] c) throws Exception{
		int i = 0 ;
		boolean isNum = false;
		Stack<String> splitStack = new Stack<>();
		splitStack.push("#");
		Stack<String> calStack = new Stack<>();
		while(c[i] != '#'){
			if(isDigit(c[i])){
				if(isNum){
					calStack.push(calStack.pop()+c[i]);
				}else{
					calStack.push(""+c[i]);
					isNum = true;
				}
			}else if(c[i] == ')'){
				isNum = false;
				String s = null;
				while(!(s = splitStack.pop()).equals("(")){
					if(!smallCal(s,calStack))
						throw new Exception();
				}
			}else{
				isNum = false;
				String s = splitStack.pop();
				while(ins(s) > outs(c[i])){
					if(!smallCal(s, calStack))
						throw new Exception();
					s = splitStack.pop();
				}
				splitStack.push(s);
				splitStack.push(c[i] + "");
			}
			i++;
		}
		while(!splitStack.isEmpty()){
			if(!smallCal(splitStack.pop(), calStack)){
				throw new Exception();
			}
		}
		return Double.parseDouble(calStack.pop());
	}

	private int outs(char c) {
		return out.get(c+"");
	}

	private int ins(String s) {
		return in.get(s);
	}

	private boolean smallCal(String s, Stack<String> calStack) {
		double a = 0;
		double b = 0;
		if(!s.equals("#")){
			try{
				b = Double.parseDouble(calStack.pop());
				a =  Double.parseDouble(calStack.pop());
			}catch(Exception e){
				return false;
			}
		}
		switch(s){
		case "+":
			calStack.push(a + b + "");
			break;
		case "-":
			calStack.push(a - b + "");
			break;
		case "*":
			calStack.push(a * b + "");
			break;
		case "/":
			calStack.push(a / b + "");
			break;
		case "^":
			calStack.push(Math.pow(a,b) + "");
			break;
		case "%":
			calStack.push(a%b + "");
			break;
		case "#":
			break;
		default:
			return false;
		}
		return true;
	}

	private boolean isDigit(char c) {
		if(c >= '0' && c <= '9' || c == '.')
			return true;
		return false;
	}
	
}
